<?php
//require_once 'admin/admin-functions.php';
require_once('facebook/facebook.php');

$facebook = new Facebook(array(
      'appId'  => '624453610898628',
      'secret' => 'f9f4673783061105bc9100feee30616c',
      'cookie' => true,
));
 
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email,offline_access,publish_stream,manage_pages'));
$logoutUrl  = $facebook->getLogoutUrl();
 
$user = $facebook->getUser();

print_r($user);
$login_params = array(
  'scope' => 'manage_pages,publish_stream',
  'redirect_uri' => 'http://www.facebook.com/TousArtistes/'
);
 
$token = $facebook->getAccessToken();
$page_id = '546429852059805';
$args = array(
    'access_token'  =>  $token,
    'message'       =>  'message',
    'link'          =>  'link',
    'caption'       =>  'caption',
    'description'   =>  'description',
);
 
$post_id = $facebook->api("/".$page_id."/feed","post",$args);

function galerie_getEditItems(){
    $numrows = $_POST['galerie-num-rows'];
    $edit = array();
    for($x=0;$x<$numrows;$x++){
        $rowID = $_POST['cb-'.$x];
        echo $_POST['cb-'.$x];
        if($_POST['cb-'.$rowID] == 'edit'){
            $edit[] = $rowID;
        }
    }
    return $edit;
}

if(isset($_POST['submit-edit'])){
        
   if(isset($_POST['submit-edit'])){
       echo $_POST['galerie-action-select']; 
    foreach ($_POST['checkbox'] as $value ) {
     echo $value;    
     //echo $_POST['statut-'.$value];
      $wpdb->update('wp_galerie', array('statut'=>$_POST['galerie-action-select']), array('id' => $value), $format = null, $where_format = null );    
      if($_POST['galerie-action-select'] == '1'){
          
      }
     }  
    } 
    /*$checked = galerie_getEditItems();
    foreach($checked as $subID){
        $newData = fm_getEditPost($subID, $cols);
        if(sizeof($newData) > 0)
            $fmdb->updateDataSubmissionRowByID($form['ID'], $subID, $newData);
    }*/
}

$photos = $wpdb->get_results("SELECT * FROM wp_galerie");
?>

<form enctype="multipart/form-data" name="galerie-admin-form" id="galerie-admin-form" action="" method="post">
   <div> 
    <select name="galerie-action-select">
        <option value="1" >Valider</option>
        <option value="0" >Hors ligne</option>
    </select>
   </div>
<div class="wrap">
		<table class="widefat post fixed" style="width:auto;">
			<?php 
			     $i =0;
			     foreach($photos as $photo){
					if(isset($photo->id)){
	
						 $id = $photo->id;
	
						
						//$i = 1;
	
						
			?>
			<tr>
			<td><input type="checkbox" name="checkbox[]" value="<?php echo $photo->id;?>"></td>
			<td><input type="hidden" name="statut-<?php echo $photo->id;?>" value="<?php echo $photo->statut;?>"></td>-->
			<td><?php echo $photo->prenom;?></td>
			<td><?php echo $photo->nom; ?></td>
			<td><?php echo $photo->cp;?></td>
			<td><?php echo $photo->statut;?></td>
			<?php
			$dirname = 'C:\xampp\htdocs\projet-lpst-wp\wp-content\photos\\'.$id.'\\';
            
                   if(is_dir($dirname)){
                       $dir = opendir($dirname);
			          while ($fichier = readdir($dir)){  
    
                        //$tab_image[$i] = $fichier;
    
                             if(is_file($dirname.$fichier)) {
                              $width = 100;
                              $image =getimagesize($dirname.'/'.$fichier);
                              $reduction = (($width * 100)/$image[0] );
                              $height = ( ($image[1] * $reduction)/100 );
			?>
			<td><img width="100px" height="<?php echo $height; ?>" src="<?php echo 'http://localhost/projet-lpst-wp/wp-content/photos/'.$id.'/'.$fichier; ?>" /></td></tr>
			<?php 
							}                           
					   }
					  }
				    }
                  $i++;
			    }?>
		</table>
		<input type="submit" name="submit-edit" id="submit-edit" class="button-primary" value="Sauvegarder" />
		<input type="hidden" name="galerie-num-rows" id="galerie-num-rows" value="<?php echo $i;?>" />
</div>
</form>
